package online_exams.controller;

import online_exams.domain.TAnswerRecordEntity;
import online_exams.service.TAnswerRecordService;
import online_exams.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;

/**
 * 答题记录表(TAnswerRecord)表控制层
 *
 * @author makejava
 * @since 2024-12-19 16:50:00
 */
@RestController
@RequestMapping("tAnswerRecord")
public class TAnswerRecordController  {
    /**
     * 服务对象
     */
    @Autowired
    private TAnswerRecordService tAnswerRecordService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public Result selectOne(@PathVariable Serializable id) {
        return Result.success(tAnswerRecordService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param TAnswerRecordEntity 实体对象
     * @return 新增结果
     */
    @PostMapping
    public Result insert(@RequestBody TAnswerRecordEntity tAnswerRecordEntity) {
        return Result.success(tAnswerRecordService.save(tAnswerRecordEntity));
    }

    /**
     * 修改数据
     *
     * @param TAnswerRecordEntity 实体对象
     * @return 修改结果
     */
    @PutMapping
    public Result update(@RequestBody TAnswerRecordEntity tAnswerRecordEntity) {
        return Result.success(tAnswerRecordService.updateById(tAnswerRecordEntity));
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @DeleteMapping
    public Result delete(@RequestParam("idList") List<Long> idList) {
        return Result.success(tAnswerRecordService.removeByIds(idList));
    }
}

